﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataWin.Core.ORM;
using DataWin.Core.Model;
using DataWin.Core.Util;
using DataWin.Core.Service;
using DWEIP.Common;
using System.Data.SqlClient;

namespace DWEIP.BLL
{
    public class BasicBLL
    {
        private static ISession _BLLSession = null;

        public static ISession BLLSession
        {
            get
            {
                if (_BLLSession==null)
                {
                    Dictionary<String, String> _Config = new Dictionary<string, string>();
                    SqlConnectionStringBuilder connectStringBuilder = new SqlConnectionStringBuilder();
                    connectStringBuilder.ConnectionString = ConfigPara.EipDBConnection;

                    //Server : 資料庫服務器
                    _Config["Server"] = connectStringBuilder.DataSource; //"192.168.104.71\\SQL2014";
                    //Database: 資料庫名稱
                    _Config["Database"] = connectStringBuilder.InitialCatalog; // "BDEMO";
                    //User: 資料庫登錄用戶
                    _Config["User"] = connectStringBuilder.UserID; // "sa";
                    //DBPassWord: 資料庫登錄口令
                    _Config["DBPassWord"] = connectStringBuilder.Password; // "sa";

                    _Config["HostName"] = "jizhen-pc";

                    _BLLSession = SessionFactory.GetInstance().OpenSession(_Config);
                }
                return _BLLSession;
            }
        }

        private static ServiceFactory _serviceFactory = null;

        private static ServiceFactory ServiceFactory
        {
            get
            {
                if (_serviceFactory==null)
                {
                    _serviceFactory.Config["HostName"] = "jizhen-pc";
                    _serviceFactory.Config["Portal"] = "WEB";
                    _serviceFactory.Config["RunPortal"] = "WEB";

                    _serviceFactory = new ServiceFactory("");
                    _serviceFactory.Initialize();
                }
                return _serviceFactory;
            }
        }
    }
}
